#!/bin/sh
# Architectural Form test: Apply two architecures (-A open -A oj)
# test onsgmls and osgmlnorm

LANG=C; export LANG
LC_ALL=C; export LC_ALL

tmpfiles=""
trap 'rm -fr $tmpfiles' 1 2 3 15

tmpfiles="$tmpfiles af-16.sgml af-16.dtd af-meta-16.dtd"
cat <<EOF >af-16.sgml
<!DOCTYPE doc SYSTEM "af-16.dtd">
<doc>
 <s>
  <v n="1">verse 1</v>
  <v n="2">verse 2</v>
 </s>
</doc>
EOF
cat <<EOF >af-16.dtd
<!NOTATION SGML PUBLIC "-//ISO 8879:1986//NOTATION Standard Generalized Markup
    Language//EN">

<?IS10744 ArcBase open>
<!NOTATION open PUBLIC "-//OpenJade Project//NOTATION AFDR ARCBASE open Architecture//EN">
<!ATTLIST #NOTATION open
    ArcDTD CDATA #FIXED "opendtd">
<!ENTITY opendtd SYSTEM "af-meta-16.dtd" CDATA SGML>

<!ELEMENT doc - o (s+)>
<!ATTLIST doc
  open NMTOKEN #FIXED "open">
<!ELEMENT s   - o (v+)>
<!ATTLIST s
  open NMTOKEN #FIXED "stanza">
<!ELEMENT v   - o (#PCDATA)>
<!ATTLIST v
  n CDATA #REQUIRED
  open NMTOKEN #FIXED "verse">
EOF

cat <<EOF >af-meta-16.dtd
<!NOTATION SGML PUBLIC "-//ISO 8879:1986//NOTATION Standard Generalized Markup
    Language//EN">

<?IS10744 ArcBase oj>
<!NOTATION oj PUBLIC "-//OpenJade Project//NOTATION AFDR ARCBASE oj Architecture//EN">
<!ATTLIST #NOTATION oj
    ArcDTD CDATA #FIXED "ojdtd">
<!ENTITY ojdtd SYSTEM "af-16-ojmeta.dtd" CDATA SGML>
<!ELEMENT open     - o (stanza+)>
<!ATTLIST open
  oj NMTOKEN #FIXED "oj">
<!ELEMENT stanza   - o (verse+)>
<!ATTLIST stanza
  oj NMTOKEN #FIXED "s">
<!ELEMENT verse    - o (#PCDATA)>
<!ATTLIST verse
  n CDATA #REQUIRED
  oj NMTOKEN #FIXED "v">
EOF
tmpfiles="$tmpfiles af-16-ojmeta.dtd"
cat <<EOF >af-16-ojmeta.dtd
<!ELEMENT oj - o (s+)>
<!ELEMENT s   - o (v+)>
<!ELEMENT v   - o (#PCDATA)>
<!ATTLIST v
  n CDATA #REQUIRED>
EOF
tmpfiles="$tmpfiles af-16-onsgmls.out"

: ${ONSGMLS=onsgmls}
${ONSGMLS} >af-16-onsgmls.out -A open -A oj af-16.sgml

tmpfiles="$tmpfiles af-16-onsgmls.ok"
cat <<EOF >af-16-onsgmls.ok
(OJ
(S
AN CDATA 1
(V
-verse 1
)V
AN CDATA 2
(V
-verse 2
)V
)S
)OJ
C
EOF

: ${DIFF=diff}
${DIFF} af-16-onsgmls.ok af-16-onsgmls.out
result=$?
test $result = 0 || { rm -fr $tmpfiles; exit 1; }

tmpfiles="$tmpfiles af-16-norm.out"
: ${OSGMLNORM=osgmlnorm}
${OSGMLNORM} >af-16-norm.out -A open -A oj af-16.sgml
tmpfiles="$tmpfiles af-16-norm.ok"
cat <<EOF >af-16-norm.ok
<OJ>
<S>
<V N="1">verse 1</V>
<V N="2">verse 2</V>
</S>
</OJ>
EOF

${DIFF} af-16-norm.ok af-16-norm.out
result=$?
test $result = 0 || result=$(($result + 1))

rm -fr $tmpfiles

exit $result
